import { getToken } from '@/request/token'
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { path: "/", component: () => import('@/views/Login') },
  {
    path: "/home", component: () => import('@/views/Home'),
    children:[
      { path: "/menu", component: () => import('@/views/menu') },
    ]
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path == '/') {
    next()
    return
  }
  if (getToken()) {
    next()
  } else {
    next('/')
  }
})
export default router
